//
//  filesystem.m
//  i18n
//
//  Created by Patrick De Caluwe on 10/8/11.
//  Copyright 2011 patrick.decaluwe@student.uclouvain.be. All rights reserved.
//

#import <UIKit/UIKit.h>
#import "filesystem.h"

@implementation filesystem

- (id)init
{
    self = [super init];
    if (self) {
        // Initialization code here.
    }
    return self;
}


- (NSString *) documentsPath 
{
    NSArray *paths = 
    NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDir = [paths objectAtIndex:0];
    return documentsDir;
}

-(void) writeToFile:(NSString *)text withFileName:(NSString *)filePath
{
    NSMutableArray *array=[[NSMutableArray alloc] init];
    [array addObject:text];
    [array writeToFile:filePath atomically:YES];
    [array release];
    
}

-(NSString *) readFromFile:(NSString *)filePath
{
    if([[NSFileManager defaultManager] fileExistsAtPath:filePath]) 
    {
        NSLog(@"le path: %@",filePath); 
        NSArray *array = [[NSArray alloc] initWithContentsOfFile:filePath];
        NSString *data= [NSString stringWithFormat:@"%@",[array objectAtIndex:0]];
        NSLog(@"le ledeuxieme: %@",array);    
        [array release];
        return data;
    }
    else
    {
        NSLog(@"File does not exist");    
        return nil;
    }
}





@end
